package alf.mapping.view.visuals;
import alf.mapping.core.Vector2d;
import alf.mapping.dto.maps.Item;
import alf.mapping.dto.maps.Link;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;

public class Sprite extends VisualElement {
	private long lastUpdate;
	private Vector2d speed;
	private float roce =  0.01f;
	private float MIN_SPEED = 10f;

	public Sprite(Item e, Bitmap b, Paint p) {
		super(e, b, p);
		speed = new Vector2d();
	}



	public void setNow(long now) {
		this.lastUpdate = now;
	}

	public void setSpeed(Vector2d newSpeed) {
		this.speed.setValores(newSpeed);
	}

	public void update(long now) {
		float progress = (now - lastUpdate);
		if (progress > 80f) {
			progress = progress / 1000f;
			Vector2d advance = speed.clone();
			advance.scale(progress);
			this.move(advance);
			lastUpdate = now;
		}
	}

	public void move(Vector2d movement) {
		this.item.getRect().offset((int)movement.getX(),(int)movement.getY());
		// frenada por rozamiento
		this.speed.decrease(roce , MIN_SPEED);

	}

	public void onDraw(Canvas canvas,Rect transf, int zoom) {
		super.onDraw(canvas,transf,zoom);
	}


}
